/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package consultorio.expedient;
import consultorio.Backup;
import consultorio.DataBase;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.*;

/**
 *
 * @author Carlos
 */
public class expedientFrame extends javax.swing.JFrame {
     private DataBase db = new DataBase();
     
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(expedientFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(expedientFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(expedientFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(expedientFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new expedientFrame().setVisible(true);
            }
        });
    }
    
     
    /**
     * Creates new form expedientFrame
     */
    public expedientFrame() {
        initComponents();

        try{
            List<String> colValue = new ArrayList();
            colValue.add("Usuario");
            colValue.add("Password");
            
            List<String> colName  = new ArrayList();
            colName.add("vcUsername");
            colName.add("vcPassword");
           
            DefaultTableModel model = db.getPatient(colName, colValue, txtSearchPatient.getText());
            tblPatient.setModel(model);
        }
        catch(Exception ex){
        
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    tblPatient = new javax.swing.JTable();
    jLabel1 = new javax.swing.JLabel();
    txtSearchPatient = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    tblPatient.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null}
      },
      new String [] {
        "Title 1", "Title 2", "Title 3", "Title 4"
      }
    ));
    jScrollPane1.setViewportView(tblPatient);

    jLabel1.setText("Paciente :");

    txtSearchPatient.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyReleased(java.awt.event.KeyEvent evt) {
        txtSearchPatientKeyReleased(evt);
      }
    });

    jButton1.setText("Enviar Email");

    jButton2.setText("Backup DB");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGap(29, 29, 29)
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(txtSearchPatient, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jButton1)
              .addComponent(jButton2))))
        .addContainerGap(47, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGap(25, 25, 25)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel1)
          .addComponent(txtSearchPatient, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jButton1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton2)))
        .addContainerGap(59, Short.MAX_VALUE))
    );

    jButton1.getAccessibleContext().setAccessibleName("btnMail");
    jButton2.getAccessibleContext().setAccessibleName("btnBackup");

    pack();
  }// </editor-fold>//GEN-END:initComponents

    
    
    private void txtSearchPatientKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchPatientKeyReleased
        
        try{
            List<String> colValue = new ArrayList();
            colValue.add("Usuario");
            colValue.add("Password");
            
            List<String> colName  = new ArrayList();
            colName.add("vcUsername");
            colName.add("vcPassword");
           
            DefaultTableModel model = db.getPatient(colName, colValue, txtSearchPatient.getText().trim());
            tblPatient.setModel(model);
        }
        catch(Exception ex){
        
        }
    }//GEN-LAST:event_txtSearchPatientKeyReleased

  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    Backup backup = new Backup();
    if(backup.create()){
      System.out.println("Backup creado de manera correcta.");
    }
    else{
      System.out.println("Ocurrio un error al intentar crear el backup de la base de datos");
    }
  }//GEN-LAST:event_jButton2ActionPerformed


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTable tblPatient;
  private javax.swing.JTextField txtSearchPatient;
  // End of variables declaration//GEN-END:variables
}
